package com.teaxiaoyi.tea_xiaoyi.controller;

import com.teaxiaoyi.tea_xiaoyi.common.AppResult;
import com.teaxiaoyi.tea_xiaoyi.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



@Api(tags = "TestController 测试接口")
@RestController
@RequestMapping("/test")
public class TestController {
    @ApiOperation(value = "测试接口1 打印hello 茶小奕")
    @RequestMapping("/hello")
    public String hello() {
        return "hello 茶小奕";
    }
    @ApiOperation(value = "测试接口2,返回 你好+传入参数")
    @GetMapping("/helloByName")
    public AppResult<String> helloByName(@ApiParam(value ="名字",required = true) String name) {
        return AppResult.success("你好"+ name);
    }
    @ApiOperation(value = "测试接口4,跳转到index.html")
    @GetMapping("/index")
    public String index() {
        return "index";
    }



    @ApiOperation(value = "测试接口3,返回一个异常结果")
    @GetMapping("/exception")
    public AppResult test() throws Exception {
        throw new Exception("这是一个exception");
    }
    @ApiOperation(value = "测试接口3,返回一个自定义异常结果")
    @GetMapping("/appException")
    public AppResult testAppException() {
        throw new ApplicationException("这是一个appException");
    }



}
